package com.mentaleye.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.mentaleye.bean.StudentPunchRecordBean;
import com.mentaleye.biz.StudentDisciplineBiz;
import com.mentaleye.biz.StudentPunchRecordBiz;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.CommonResult;
import com.mentaleye.util.DateFormatter;

@Controller
@RequestMapping("/punchRecordController")
public class StudentPunchRecordController {
	@Autowired
	private StudentPunchRecordBiz punchRecordBiz;
	
	@Autowired StudentDisciplineBiz disciplineBiz;
	
	@RequestMapping("/toListPage")
	public ModelAndView toListPage(@RequestBody StudentPunchRecordBean recordBean) {
		ModelAndView view=new ModelAndView("/lm/attendance/studentPunchList");
		view.addObject("studentId", recordBean.getStudentId());
		view.addObject("writeTime", DateFormatter.format(recordBean.getWriteTime(),"yyyy-MM"));
		return view;
	}

	@RequestMapping("/toEditPage")
	public ModelAndView toEditPage(@RequestParam Long recordId) {
		ModelAndView view=new ModelAndView("/lm/attendance/studentPunchEdit");
		view.addObject("beanList", this.disciplineBiz.getBeanList());
		view.addObject("punchBean", this.punchRecordBiz.getBeanByKey(recordId));
		return view;
	}
	
	@RequestMapping("/updateRecordByFile")
	@ResponseBody
	public String updateRecordByFile(@RequestParam String fileName,HttpServletRequest request) {
		CommonResult result = this.punchRecordBiz.updateByFile(fileName,request);
		return JSONObject.toJSONString(result);
	}    
	
	@RequestMapping("/updateData")
	@ResponseBody
	public String updateData(@RequestBody StudentPunchRecordBean recordBean){
		CommonResult result=this.punchRecordBiz.updateRecord(recordBean);
		return JSONObject.toJSONString(result);
	}
	
	@RequestMapping("/getList")
	@ResponseBody
	public String getList(CommonPage page) {
		this.punchRecordBiz.getListByPage(page);
		return page.toSHowPage();
	}
	
}
